package com.qf.commerce.controller;

import com.github.pagehelper.PageInfo;
import com.qf.commerce.common.dto.SeckillActivityDto;
import com.qf.commerce.common.vo.SeckillActivityVo;
import com.qf.commerce.exception.ControllerException;
import com.qf.commerce.resp.ResponseResult;
import com.qf.commerce.resp.ResponseStatus;
import com.qf.commerce.service.SeckillActivityService;
import org.springframework.util.ObjectUtils;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

@RestController
@RequestMapping("/seckill/activity")
public class SeckillActivityController {
    @Resource
    SeckillActivityService seckillActivityService;
    @GetMapping("/query")
    public ResponseResult<PageInfo<SeckillActivityVo>> querySeckillActivity(@RequestParam(defaultValue = "1")Integer page,@RequestParam(defaultValue = "10")Integer size, SeckillActivityDto seckillActivityDto){
        if(ObjectUtils.isEmpty(seckillActivityDto)){
            throw new ControllerException(ResponseStatus.GET_DATA_ERROR);
        }
        return ResponseResult.success(seckillActivityService.querySeckillActivity(page,size,seckillActivityDto));
    }
    //批量删除
    @DeleteMapping("/del")
    public ResponseResult<Integer> delById(@RequestBody List<Long> seckillActivityId){
        if(ObjectUtils.isEmpty(seckillActivityId)){
            throw new ControllerException(ResponseStatus.GET_DATA_ERROR);
        }
        return ResponseResult.success(seckillActivityService.delById(seckillActivityId));
    }
    //批量启用
    @PutMapping("/up/status")
    public ResponseResult<Integer> upStatusById(@RequestBody List<Long> seckillActivityId){
        if(ObjectUtils.isEmpty(seckillActivityId)){
            throw new ControllerException(ResponseStatus.GET_DATA_ERROR);
        }
        return ResponseResult.success(seckillActivityService.upStatusById(seckillActivityId));
    }
    //批量停用
    @PutMapping("/up/activity/status")
    public ResponseResult<Integer> upAcivityStatusById(@RequestBody List<Long> seckillActivityId){
        if(ObjectUtils.isEmpty(seckillActivityId)){
            throw new ControllerException(ResponseStatus.GET_DATA_ERROR);
        }
        return ResponseResult.success(seckillActivityService.upStatusById(seckillActivityId));
    }
    //修改活动信息以及秒杀商品信息
    @PutMapping("/up/activity")
    public ResponseResult<Integer> upActivity(@RequestBody SeckillActivityDto seckillActivityDto){
        if(ObjectUtils.isEmpty(seckillActivityDto)){
            throw new ControllerException(ResponseStatus.GET_DATA_ERROR);
        }
        return ResponseResult.success(seckillActivityService.upActivity(seckillActivityDto));
    }

    @PostMapping("/add/activity")
    public ResponseResult<Integer> addActivity(@RequestBody SeckillActivityDto seckillActivityDto){
        if(ObjectUtils.isEmpty(seckillActivityDto)){
            throw new ControllerException(ResponseStatus.GET_DATA_ERROR);
        }
        return ResponseResult.success(seckillActivityService.addActivity(seckillActivityDto));
    }


}
